var combinationSum2 = function (candidates, target) {
  let res = []
  candidates.sort((a, b) => {
    return a - b
  })
  const dfs = (startIndex, path, sum) => {
    if (sum === target) {
      res.push([...path])
      return
    }
    if (sum > target) {
      return
    }
    for (let i = startIndex; i < candidates.length; i++) {
      if (candidates[i] > target) {
        continue
      }
      if (i - startIndex > 0 && candidates[i - 1] === candidates[i]) {
        continue
      }
      path.push(candidates[i])
      dfs(i + 1, path, sum + candidates[i])
      path.pop()
    }
  }
  dfs(0, [], 0)
  return res
};

let candidates = [10, 1, 2, 7, 6, 1, 5], target = 8
combinationSum2(candidates, target)